<template>
  <div v-loading="loading">
    <div class="add_btn_top">
      <el-button size="mini" @click="$router.go(-1)">返 回</el-button>
      <!-- <el-button
        type="primary"
        size="mini"
        icon="el-icon-printer"
        v-print="printObj"
        >打 印</el-button
      > -->
      <el-button size="mini" @click="handleEdit" icon="el-icon-edit-outline"
        >编 辑</el-button
      >
      <el-button
        v-permission="[2, 'button']"
        type="danger"
        size="mini"
        icon="el-icon-delete"
        @click="deleteBtn"
        >删 除</el-button
      >
      <!-- <el-button size="mini" @click="handleEmport"
        ><svg-icon
          class="svg-icon"
          icon-class="export"
          style="margin-right: 4px"
        />导 出</el-button
      > -->
    </div>
    <!-- <pdf id="printTab" :src="src" ref="pdf"></pdf> -->

    <iframe
      v-init-screen-h="10"
      style="width: 100%"
      :src="src"
      frameborder="0"
    ></iframe>

    <AddDialog
      :mainToken="token"
      :showDialog.sync="showDialog"
      :isedit="true"
      :title="title"
      @closeDialog="closeDialog"
      ref="addDialogRef"
    ></AddDialog>
  </div>
</template>

<script>
import AddDialog from "./AddDialog.vue";
// import pdf from "vue-pdf-signature";
// import CMapReaderFactory from "vue-pdf-signature/src/CMapReaderFactory";
import { getTechnologyToken, delTechnology } from "@/api/technology";
import { download } from "@/utils/download";
// import pdf from "vue-pdf-signature";
// import CMapReaderFactory from "vue-pdf-signature/src/CMapReaderFactory";

import { filtersFileUrl } from "@/filter/index";
export default {
  components: {
    // pdf,
    AddDialog,
  },
  data() {
    return {
      title: "主工艺",
      token: "",
      tabHtml: "",
      details: { metadata: { url: "" }, name: "" },
      minioClient: null,
      src: "",
      numPages: 0,
      page: 1,
      currentPage: 0,
      showDialog: false,
      loading: false,
      printObj: {
        id: "printTest",
        popTitle: "",
        extraHead: "",
      },
    };
  },
  mounted() {
    this.token = this.$route.query.token;
    this.init();
  },
  methods: {
    closeDialog(isRefresh, token) {
      // isRefresh是否刷新
      if (isRefresh) {
        // this.init();
        if (token) {
          this.$router.replace({
            name: "mainExhibition",
            query: {
              token,
            },
          });
          this.token = token;
          this.init();
        }
      }
      this.showDialog = false;
    },
    handleEdit(token) {
      this.showDialog = true;
    },
    init() {
      getTechnologyToken(this.token, false)
        .then((res) => {
          const { data } = res;
          this.details = data;
          // this.printObj.popTitle = data.name;
          this.src = `${process.env.VUE_APP_JIMU_URL}/jmreport/view/${data.reportId}?token1=${data.token}&token2=${data.token}&Authorization=Bearer ${this.$store.state.user.accessToken}`;
          // 打印之后保存pdf的文件名字
          // document.title = data.name || "工艺模板";
        })
        .finally((f) => {
          // this.loading = false;
        });
    },
    //删除
    deleteBtn() {
      this.$confirm("是否确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        await delTechnology(this.token);
        this.$msg({
          type: "success",
          message: "删除成功!",
        });
        this.$router.push({
          name: "mainList",
        });
      });
    },

    handleEmport() {
      download(this.details.url, this.details.name || this.details.token);
    },
  },
};
</script>


<style lang='scss' scoped>
.tem_title {
  text-align: center;
  font-size: 34px;
  font-weight: bold;
  padding: 20px 0;
}

.tem_pdf {
  border: 1px solid rgba(0, 0, 0, 0.1);
  width: 98%;
  margin: 0 auto;
  border-radius: 6px;
  overflow: hidden;
  padding: 10px;
}
</style>